import getApiData, { getNestApiData } from "@/services/cpasRequest";

export async function getfindDesignTableName(params: {
    design_tableName: string;
    dbname: string;
}) {
    const res = await getApiData("account.findDesignTableName", params);
    if (res.ok) {
        return Promise.resolve({
            data: res.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: res.data,
        success: false,
    });
};


export async function getjudgmentInit(params: {
    dbname: string;
    type: string;
    tableName?: string;
    tableRealName?: string;
}) {
    try {
        const res = await getApiData("account.judgmentInit", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: '接口account.judgmentInit出错了！',
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: '接口account.judgmentInit出错了！',
            success: false,
        });
    }
};

export async function getSeekAuditReportTemplate(params: {
    zcbfid: string;
}) {
    try {
        const res = await getApiData("account.seekAuditReportTemplate", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: '接口account.seekAuditReportTemplate出错了！',
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: '接口account.seekAuditReportTemplate出错了！',
            success: false,
        });
    }
};


// 初始化模板
export async function templateInitApi(params: {
    dbName: string;
    templateName: string;
    tableNames: string[];
    type: string;
    dataId?: string;
    opt?: {
        duplicate: string
    }
}) {
    try {
        const res = await getNestApiData('/template/importTemplate', 'post', params)
        if (res.ok) {
            return Promise.resolve({
                data: res.ok,
                msg: res.msg,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.ok,
            msg: res.msg,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: '接口/template/importTemplate,请求失败！',
            success: false,
        });
    }
};



// 校验结果
export async function gettableIsVerifyList(params: {
    tableName: string;
    dbname: string;
    isTid: boolean
}) {
    try {
        const res = await getApiData("account.design_table.isVerifyAndTid", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: '接口account.design_table.isVerifyAndTid出错了！',
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: '接口account.design_table.isVerifyAndTid出错了！',
            success: false,
        });
    }
}
